import { createRouter, createWebHistory } from 'vue-router'
import MainLayout from '@/layouts/MainLayout.vue'
import { setupRouterGuards } from './guards'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    // 登录页面
    {
      path: '/login',
      name: 'Login',
      component: () => import('@/views/auth/LoginView.vue')
    },
    // 主布局 - 只保留基础路由
    {
      path: '/',
      name: 'MainLayout',
      component: MainLayout,
      redirect: '/dashboard',
      children: [
        {
          path: 'dashboard',
          name: 'Dashboard',
          component: () => import('@/views/DashboardView.vue'),
          meta: { breadcrumb: ['首页', '仪表盘'] }
        },
        // 404页面
        {
          path: '404',
          name: 'NotFound',
          component: () => import('@/views/common/NotFoundView.vue'),
          meta: { breadcrumb: ['首页', '页面未找到'] }
        }
      ]
    },
    // 捕获所有未匹配的路由
    {
      path: '/:pathMatch(.*)*',
      redirect: '/404'
    }
  ]
})

// 设置路由守卫
setupRouterGuards(router)

export default router